namespace AltNetUK.Models
{
    using System;
    using System.Text;
    using System.Xml.Serialization;

    [XmlRoot(ElementName = "address")]
    public sealed class Address
    {
        public static implicit operator string(Address address)
        {
            return (null == address) ? null as string : address.ToString();
        }

        [XmlAttribute(AttributeName = "street")]
        public string Street
        {
            get;
            set;
        }

        [XmlAttribute(AttributeName = "locality")]
        public string Locality
        {
            get;
            set;
        }

        [XmlAttribute(AttributeName = "postal-code")]
        public string PostalCode
        {
            get;
            set;
        }

        [XmlAttribute(AttributeName = "country")]
        public string Country
        {
            get;
            set;
        }

        public override string ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append(this.Street);
            if (0 != buffer.Length)
            {
                buffer.Append(", ");
            }

            buffer.Append(this.Locality);
            if (0 != buffer.Length)
            {
                buffer.Append(", ");
            }

            buffer.Append(this.PostalCode);
            if (0 != buffer.Length)
            {
                buffer.Append(", ");
            }

            buffer.Append(this.Country);

            return buffer.ToString();
        }
    }
}